<?php 
session_start();
include "fungsi.php";
include "SimpleImage.php";
$nama = $_SESSION['username'];
$hak = $_SESSION['hak_akses'];
$baru = new fungsi();
$baru->konek();
	if($_POST){
		$nama_produk				= $_POST['nama'];
		$deskripsi_produk 			= $_POST['deskripsi'];
		$gambar						= $_FILES['gambar']['name'];
		$type 						= pathinfo($_FILES['gambar']['name']);
	
		if($type['extension'] == "jpg" || $type['extension'] == "png"){
			$fileName = $_FILES['gambar']['name'];
			$fileSize = $_FILES['gambar']['size'];
			$fileError = $_FILES['gambar']['error'];
			
			if($fileSize > 0 || $fileError == 0){
				if(file_exists("images/".$fileName)){
					unlink("images/".$fileName);
				}
				$image = new SimpleImage();
				$image->load($_FILES['gambar']['tmp_name']);
				$image->resize(150,150);
				$image->save("images/".$fileName);
				$move = file_exists("images/".$fileName);
				
				if($move){
					$sql = "insert into produk (kode_akun, kode_produk, nama_produk,deskripsi_produk,gambar) values ('".$hak."',' ','".$nama_produk."','".$deskripsi_produk."','images/".$gambar."')";
					$kueri = mysql_query($sql) or die(mysql_error());
					if($kueri){
//						echo $gambar;
						?>
						<script language="javascript" >
						alert ("Produk Telah Ditambahkan ");
						document.location= 'form-daftar-produk.php';
						</script>
						<?php
					}
					else
					{
						echo "Data Gagal dimasukan<br><a href=form.php>Kembali</a>";
					}
				}else{
					echo "<script>alert('Terjadi error');</script>";
				}
			}
		}
	}



	
?>